package com.epfresh.supplier.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.epfresh.api.utils.MarketPermissionUtil;
import com.epfresh.supplier.Listener.IndexIconOnClickListener;
import com.epfresh.supplier.R;
import com.epfresh.supplier.entity.HomePart;
import com.epfresh.supplier.widget.CommonRecyclerAdapter;
import com.epfresh.supplier.widget.ViewHolder;

import java.util.List;

public class HomePartTopSmallAdapter extends CommonRecyclerAdapter<HomePart> {
    private IndexIconOnClickListener indexIconOnClickListener;
    private boolean isShowRedPoint = false;

    public HomePartTopSmallAdapter(Context context, List<HomePart> datas) {
        super(context, datas, R.layout.index_top_samll_item);
    }

    public void setShowRedPoint(boolean isShowRedPoint) {
        this.isShowRedPoint = isShowRedPoint;
    }

    public void setDatas(List<HomePart> datas) {
        super.setData(datas);
    }

    public void setListener(IndexIconOnClickListener indexIconOnClickListener) {
        this.indexIconOnClickListener = indexIconOnClickListener;
    }

    @Override
    public void convert(ViewHolder holder, final HomePart item, int position) {
        ImageView pic = holder.getView(R.id.iv_pic);
        ImageView ivPoint = holder.getView(R.id.iv_point);
        LinearLayout llIcon = holder.getView(R.id.ll_icon);
        switch (item.getName()) {
            case MarketPermissionUtil.marketOis:
                pic.setBackgroundResource(R.mipmap.entry_registration_top);
                ivPoint.setVisibility(View.INVISIBLE);
                break;
            case MarketPermissionUtil.marketDetection:
                pic.setBackgroundResource(R.mipmap.presentation_top);
                ivPoint.setVisibility(View.INVISIBLE);
                break;
            case MarketPermissionUtil.marketMyDetection:
                pic.setBackgroundResource(R.mipmap.mycontract_top);
                ivPoint.setVisibility(View.INVISIBLE);
                break;
            case MarketPermissionUtil.marketMyCar:
                pic.setBackgroundResource(R.mipmap.mycar_top);
                ivPoint.setVisibility(View.INVISIBLE);
                break;
            case MarketPermissionUtil.marketPreRegistration:
                pic.setBackgroundResource(R.mipmap.register_top);
                ivPoint.setVisibility(View.INVISIBLE);
                break;
            case MarketPermissionUtil.marketPay:
                pic.setBackgroundResource(R.mipmap.pay_top);
                if (isShowRedPoint) {
                    ivPoint.setVisibility(View.VISIBLE);
                } else {
                    ivPoint.setVisibility(View.INVISIBLE);
                }
                break;
            case MarketPermissionUtil.appSupplierOrder:
                pic.setBackgroundResource(R.mipmap.order_top);
                ivPoint.setVisibility(View.INVISIBLE);
                break;
            case MarketPermissionUtil.appSupplierProductSelling:
                pic.setBackgroundResource(R.mipmap.spot_commodity_top);
                ivPoint.setVisibility(View.INVISIBLE);
                break;
            case MarketPermissionUtil.appSupplierIncome:
                pic.setBackgroundResource(R.mipmap.my_income_top);
                ivPoint.setVisibility(View.INVISIBLE);
                break;
            case MarketPermissionUtil.appSupplierProductStanding_book:
                pic.setBackgroundResource(R.mipmap.my_ledger_top);
                ivPoint.setVisibility(View.INVISIBLE);
                break;
            case MarketPermissionUtil.appSupplierOrderJmt:
                pic.setBackgroundResource(R.mipmap.waiver_top);
                ivPoint.setVisibility(View.INVISIBLE);
                break;
            case MarketPermissionUtil.appSupplierEmployee:
                pic.setBackgroundResource(R.mipmap.staff_management_top);
                ivPoint.setVisibility(View.INVISIBLE);
                break;
            case MarketPermissionUtil.appSupplierProductPurchase:
                pic.setBackgroundResource(R.mipmap.stock_management_top);
                ivPoint.setVisibility(View.INVISIBLE);
                break;
            case MarketPermissionUtil.appSupplierCustomer:
                pic.setBackgroundResource(R.mipmap.customer_management_top);
                ivPoint.setVisibility(View.INVISIBLE);
                break;
            case MarketPermissionUtil.appSupplierProductPrice:
                pic.setBackgroundResource(R.mipmap.changemoney_top);
                ivPoint.setVisibility(View.INVISIBLE);
                break;
            case MarketPermissionUtil.appSupplierToIncome:
                pic.setBackgroundResource(R.mipmap.collection_top);
                ivPoint.setVisibility(View.INVISIBLE);
                break;
            case MarketPermissionUtil.appSupplierStore:
                pic.setBackgroundResource(R.mipmap.my_stores_top);
                ivPoint.setVisibility(View.INVISIBLE);
                break;
            case MarketPermissionUtil.appSupplierProductPresell:
                pic.setBackgroundResource(R.mipmap.pre_sale_goods_top);
                ivPoint.setVisibility(View.INVISIBLE);
                break;
            case MarketPermissionUtil.appSupplierJointOrder:
                pic.setBackgroundResource(R.mipmap.stock_up_top);
                ivPoint.setVisibility(View.INVISIBLE);
                break;
            case MarketPermissionUtil.appSupplierProductOften_order:
                pic.setBackgroundResource(R.mipmap.grab_sheet_top);
                ivPoint.setVisibility(View.INVISIBLE);
                break;
            case MarketPermissionUtil.appSupplierComment:
                pic.setBackgroundResource(R.mipmap.evaluate_top);
                ivPoint.setVisibility(View.INVISIBLE);
                break;
            case MarketPermissionUtil.appSupplierCoupon:
                pic.setBackgroundResource(R.mipmap.coupon_top);
                ivPoint.setVisibility(View.INVISIBLE);
                break;
            case MarketPermissionUtil.appSupplierJointProduct:
                pic.setBackgroundResource(R.mipmap.offer_top);
                ivPoint.setVisibility(View.INVISIBLE);
                break;
        }
        llIcon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (indexIconOnClickListener != null) indexIconOnClickListener.onclick(item.getName());
            }
        });

    }
}
